<!doctype html>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<title>钢链网-我的订单</title>
	<link rel="stylesheet" href="/resource/css/gl_index.css">
	<link rel="stylesheet" href="/resource/css/gl_user.css">
	<link rel="stylesheet" href="/resource/css/gl_showBo.css">

	<script src="/resource/js/jquery-1.11.3.min.js"></script>
	<script src="/resource/js/gl_index.js"></script>
	<script src="/resource/js/gl_showBo.js"></script>
	<script>
		$(function(){
			var popup_cancel = '<div class="popup-show popup-cancel">';
			popup_cancel += '<div class=\"popup-p\">';
			popup_cancel +='<i><img src=\"./resource/img/gl_show_err.png\" alt=""></i>';
			popup_cancel +='<div class=\"left\">';
			popup_cancel +='确定要取消订单？<br/>';
			popup_cancel +='<div class="btn"><a href="javascript:;" class="deter">确定</a>';
			popup_cancel +='<a href="javascript:;" class="close">取消</a></div>';
			popup_cancel +='</div><div class=\"popup-close\"></div></div></div>';
			var popup_del = '<div class="popup"></div><div class="popup-show popup-del">';
			popup_del += '<div class=\"popup-p\">';
			popup_del +='<i><img src=\"./resource/img/gl_show_err.png\" alt=""></i>';
			popup_del +='<div class=\"left\">';
			popup_del +='确定要删除订单？<br/>';
			popup_del +='<div class="btn"><a href="javascript:;" class="deter">确定</a>';
			popup_del +='<a href="javascript:;" class="close">取消</a></div>';
			popup_del +='</div><div class=\"popup-close\"></div></div></div>';
			var popup = '<div class="popup-show popup-goods">';
			popup += '<div class=\"popup-p\">';
			popup +='<i><img src=\"/resource/img/gl_show_succ.png\" alt=""></i>';
			popup +='<div class=\"left\">';
			popup +='请确认您已经收到货，确认后可申请开票<br/>';
			popup +='<div class="btn"><a href="javascript:;" class="deter">确定</a>';
			popup +='<a href="javascript:;" class="close">取消</a></div>';
			popup +='</div><div class=\"popup-close\"></div></div></div>';
			$('body').append(popup_del+popup_cancel+popup);
			$('.popup-show').css('margin-left',-$('.popup-show').width()/2);
			//点击确认提货
			$(document).delegate('.confirm','click',function(){
				var order_id = $(this).attr('rel');
				$('.popup-goods .deter').attr('order_id',order_id);
				$('.popup-goods').show();
				$('.popup').show();
			});
			$(document).delegate('.popup-goods .deter','click',function(){
				var order_id = $(this).attr('order_id');
				$.ajax({
					url : '/confirm_receipt',
					type : "POST",
					data : {order_id:order_id},
					dataType : "json",
					cache:"false",
					timeout:30000,
					success : function(json) {
						if (json){
							location=location
						}
					}
				});

			});
			//取消订单
			$(document).delegate('.cancel','click',function(){
				var order_id = $(this).attr('rel');
				var status = $(this).attr('status');
				$('.popup-cancel .deter').attr('order_id',order_id);
				$('.popup-cancel .deter').attr('status',status);
				$('.popup-cancel').show();
				$('.popup').show();
			});
			$(document).delegate('.popup-cancel .deter','click',function(){
				var order_id = $(this).attr('order_id');
				var status = $(this).attr('status');
				if(status == 10){
					$.ajax({
						url : '/cancel_order_no_lock',
						type : "POST",
						data : {order_id:order_id},
						dataType : "json",
						cache:"false",
						timeout:30000,
						success : function(json) {
							if(json.code == 1){
								location=location
							}else{

							}
						}
					});
				}else if(status == 20){
					$.ajax({
						url : '/cancel_order_no_pay',
						type : "POST",
						data : {order_id:order_id},
						dataType : "json",
						cache:"false",
						timeout:30000,
						success : function(json) {
							if(json.code == 1){
								location=location
							}else{

							}
						}
					});
				}
			});
			//删除订单
			$(document).delegate('.del','click',function(){
				var order_id = $(this).attr('rel');
				$('.popup-del .deter').attr('order_id',order_id);
				$('.popup-del').show();
				$('.popup').show();
			});
			$(document).delegate('.popup-del .deter','click',function(){
				var order_id = $(this).attr('order_id');
				$.ajax({

					url : '/del_order_pc',
					type : "POST",
					data : {order_id:order_id},
					dataType : "json",
					cache:"false",
					timeout:30000,
					success : function(json) {
						if(json.code == 1){
							location=location
						}else{

						}
					}
				});
			});
			//开票
			$('.btn-open').click(function () {
				var order_id = $(this).attr('rel');
				$('.btn-billing').attr('order_id',order_id);
			});
			$('input.form-control').after('<span>11</span>');
			$('input.form-control').blur(function(){
				if(!$(this).val()){
					$(this).siblings('span').show().html('不能为空');
				}else{
					$(this).siblings('span').hide();
				}
			});
			$('.btn-billing').click(function(){
				var bill = [];
				var order_id = $(this).attr('order_id');
				for (var i = 0; i < $('input.form-control').length; i++) {
					if(!$('input.form-control').eq(i).val()){
						$('input.form-control').eq(i).focus().siblings('span').show().html('不能为空');
						return false;
					}else{
						bill.push($('input.form-control').eq(i).val());
					}
				};
				$('.popup-billing').hide();
				$('.popup').hide();
				$.ajax({
					url : '/add_invoice',
					type : "POST",
					data : {order_id:order_id,title:bill[0],address:bill[1],addressee:bill[2],phone:bill[3]},
					dataType : "json",
					cache:"false",
					timeout:30000,
					success : function(json) {
						Showbo.Msg.nameauth('<img src="/resource/img/gl_show_succ.png" style="margin-top:20px;"><div style="font-size:24px;">已确认开票</div><div style="margin-bottom:25px;line-height:38px;font-size:14px;color:#656464;">开票完成后，我们会尽快将发票寄到您的手中</div>',function(){
							location=location
						});
					}
				});

			});
			$.ajax({
				url : '/user_order_num',
				type : "POST",
				data : {status:10},
				dataType : "json",
				cache:"false",
				timeout:30000,
				success : function(json) {

					if(json.code > 0){
						//	console.log(json.code);
						$('.order-ul li').eq(1).find('span').html(json.code);
					}
				}
			});
			$.ajax({
				url : '/user_order_num',
				type : "POST",
				data : {status:20},
				dataType : "json",
				cache:"false",
				timeout:30000,
				success : function(json) {

					if(json.code > 0){
						//	console.log(json.code);
						$('.order-ul li').eq(2).find('span').html(json.code);
					}
				}
			});
			$.ajax({
				url : '/user_order_num',
				type : "POST",
				data : {status:30},
				dataType : "json",
				cache:"false",
				timeout:30000,
				success : function(json) {

					if(json.code > 0){
						//	console.log(json.code);
						$('.order-ul li').eq(3).find('span').html(json.code);
					}
				}
			});
			$.ajax({
				url : '/user_order_num',
				type : "POST",
				data : {status:40},
				dataType : "json",
				cache:"false",
				timeout:30000,
				success : function(json) {

					if(json.code > 0){
						$('.order-ul li').eq(4).find('span').html(json.code);
					}
				}
			});
		});
	</script>

</head>
<body>
<div class="head">
	@include('common.user_head')
</div>
<div class="user-head">
	<div class="main">
		<div class="logo">
			<a href="/"><img src="/resource/img/logo.png" alt=""></a>
			<div>我的钢链网
				<a href="/">返回首页</a>
			</div>
		</div>
	</div>
</div>	
<div class="user main">
	@include('common.user_menu')
	<div class="user-cont">
		<div class="order">
			<div class="title">我的订单</div>
			<div class="order-ul">
				<ul>
					<li class="active"><a href="/user_order?status=0">全部订单</a></li>
					<li><a href="/user_order?status=10">待审核<span></span></a></li>
					<li><a href="/user_order?status=20">待付款<span></span></a></li>
					<li><a href="/user_order?status=30">待提货<span></span></a></li>
					<li><a href="/user_order?status=40">待开票<span></span></a></li>
				</ul>
			</div>
			<div class="order-table">
				<table>
					@if(!empty($data))
					<thead>
						<tr>
							<th width="227px">订单商品</th>
							<th width="228px">支付总金额</th>
							<th width="227px">订单状态</th>
							<th width="">操作</th>
						</tr>
					</thead>

					@foreach($data as $key  => $data1)
						<tbody>
						<tr class="bg">
							<td colspan="4"></td>
						</tr>
						<tr class="tr-head">
							<td colspan="4">
								{{date("Y-m-d H:i:s", $data1->order_time)}} <span><i>订单编号：</i>{{$data1->order_sn}}</span>
							</td>
						</tr>
						<tr class="tr-info">
							<td>
								<div>
									{{$data1->brand_name}}
									<span>{{$data1->product_spec}}   {{$data1->m_name}} <br/>{{$data1->factory_name}}</span>
								</div>
							</td>
							<td>
								<div>
									<i>￥{{$data1->amount}}</i>
									@if($data1->payment_id == 0)
										<span>京东在线支付</span>
										@elseif($data1->payment_id == 1)
										<span>现金支付</span>
										@elseif($data1->payment_id == 2)
										<span>银行汇款支付</span>
										@elseif($data1->payment_id == 3)
										<span>银承兑行汇票</span>
										@else
									@endif
								</div>
							</td>
							@if($data1->order_status == 10)
								<td><div>等待审核</div></td>
								<td>
									<a href="/order_details?order_id={{$data1->order_id}}">订单详情</a>
									<a href="javascript:;" class="cancel" rel="{{$data1->order_id}}"  status ="{{$data1->order_status}}">取消订单</a>
								</td>
							@elseif($data1->order_status == 20)
								<td><div>等待支付</div></td>
								<td>
									<a href="/jd_pay_first?order_id={{$data1->order_id}}" class="btn-pay">立即付款</a>
									<a href="/order_details?order_id={{$data1->order_id}}">订单详情</a>
									<a href="javascript:;" class="cancel" rel="{{$data1->order_id}}"  status ="{{$data1->order_status}}">取消订单</a>
								</td>
							@elseif($data1->order_status == 30)
								<td><div>等待提货</div></td>
								<td>
									<a href="javascript:;" class="btn-th confirm" rel="{{$data1->order_id}}">确认提货</a>
									<a href="/order_details?order_id={{$data1->order_id}}">订单详情</a>
								</td>
							@elseif($data1->order_status == 40)
								<td><div>等待开票</div></td>
								<td>
									<a href="javascript:;" class="btn-open billing" rel="{{$data1->order_id}}">立即开票</a>
									<a href="/order_details?order_id={{$data1->order_id}}" >订单详情</a>
								</td>
							@elseif($data1->order_status == 50)
								<td><div>交易成功</div></td>
								<td>
									<a href="/order_details?order_id={{$data1->order_id}}">订单详情</a>
									<a href="javascript:;" class="del" rel="{{$data1->order_id}}">删除订单</a>
								</td>
							@elseif($data1->order_status == 60)
								<td><div>订单取消</div></td>
								<td>
									<a href="/order_details?order_id={{$data1->order_id}}">订单详情</a>
									<a href="javascript:;" class="del" rel="{{$data1->order_id}}">删除订单</a>
								</td>

							@endif

						</tr>
						</tbody>
					@endforeach
						@else
						<div class="order-no">
							<img src="/resource/img/order_no.png" alt="">没有相关订单
						</div>
						@endif


				</table>
			</div>
		</div>
	</div>
</div>
<!-- 立即开票弹窗 -->
<div class="popup-billing">
	<form action="">
		<div class="title">
			填写发票信息
			<div class="close"></div>
		</div>
		@foreach($data as $key  => $data1)
		@endforeach
		<div class="form">
			<div class="form-group">
				<label for="">公司抬头：</label>
				<input type="text" class="form-control">
			</div>
			<div class="form-group">
				<label for="">邮寄地址：</label>
				<input type="text" class="form-control">
			</div>
			<div class="form-group">
				<label for="">联 系 人：</label>
				<input type="text" class="form-control">
			</div>
			<div class="form-group">
				<label for="">联系电话：</label>
				<input type="text" class="form-control">
			</div>
			<input type="button" class="btn-billing" value="确认开票">
		</div>
	</form>
</div>
@include('common.shop_foot')
</body>
</html>